package edu.bbk.muc.lifetracker.common;

import com.google.gson.Gson;

/**
 * Instances of {@link Event} will be returned from sensor layer. Each method
 * should return either value or <code>null</code> if value has not been set.
 * @author irenatyler and romankirillov
 */
public class Event implements Comparable<Event> {
  private static final Gson gson = new Gson();

  public static Event fromJSON(String data) {
    return gson.fromJson(data, Event.class);
  }

  private Acceleration acceleration;
  private Float ambientLight;
  private SimpleLocation location;

  private Long timestamp;

  public Event() {
  }

  public Event(Long timestamp,
               Acceleration acceleration,
               Float ambientLight,
               SimpleLocation location) {
    this.timestamp = timestamp;
    this.acceleration = acceleration;
    this.ambientLight = ambientLight;
    this.location = location;
  }

  @Override
  public int compareTo(Event arg0) {
    /**
     * This is ugly hack - there's no .compare method for integer primitives in
     * standard Java and I can't bother to write one. Besides, double will do
     * the job (and is, supposedly, long enough not to break here).
     */
    return Double.compare(this.timestamp, arg0.timestamp);
  }

  public Acceleration getAcceleration() {
    return acceleration;
  }

  public Float getAmbientLight() {
    return ambientLight;
  }

  public SimpleLocation getLocation() {
    return location;
  }

  public Long getTimestamp() {
    return timestamp;
  }

  public void setAcceleration(Acceleration acceleration) {
    this.acceleration = acceleration;
  }

  public void setAmbientLight(Float ambientLight) {
    this.ambientLight = ambientLight;
  }

  public void setLocation(SimpleLocation location) {
    this.location = location;
  }

  public void setTimestamp(Long timestamp) {
    this.timestamp = timestamp;
  }

  public String toJSON() {
    return gson.toJson(this);
  }
}
